<?php

namespace App\Library\Rules;

use Illuminate\Contracts\Validation\Rule;

class SerialNumbersRule extends BaseRule implements Rule
{
    private string $errorMessage = '编号格式错误';

    /**
     * Desc:
     * @param string $attribute
     * @param mixed $value
     * @return boolean
     */
    public function passes($attribute, $value): bool
    {
        foreach ($value as $v) {
            if (!is_string($v)) return false;
            else if (strlen($v) !== 20) return false;
            else if (!preg_match(__('com.numReg'), $v)) return false;
        }
        return true;
    }

    /**
     * Desc:
     * @return string
     */
    public function message(): string
    {
        return $this->errorMessage;
    }
}
